<?php
/**
 * Magento
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Academic Free License (AFL 3.0)
 * that is bundled with this package in the file LICENSE_AFL.txt.
 * It is also available through the world-wide-web at this URL:
 * http://opensource.org/licenses/afl-3.0.php
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@magentocommerce.com so we can send you a copy immediately.
 *
 * DISCLAIMER
 *
 * Do not edit or add to this file if you wish to upgrade Magento to newer
 * versions in the future. If you wish to customize Magento for your
 * needs please refer to http://www.magentocommerce.com for more information.
 *
 * @copyright   Copyright (c) 2014 X.commerce, Inc. (http://www.magentocommerce.com)
 * @license     http://opensource.org/licenses/afl-3.0.php  Academic Free License (AFL 3.0)
 */
?>
<?php /* @var $this \Magento\Paypal\Block\Billing\Agreement\View */ ?>
    <div class="block block-billing-agreements-view">
        <div class="block-title">
            <strong><?php echo __('Billing Agreement # %1', $this->escapeHtml($this->getReferenceId())) ?></strong>
            <?php if ($this->getCanCancel()): ?>
                <button type="button" title="<?php echo __('Cancel') ?>" class="secondary action cancel" onclick="if( confirm('<?php echo __('Are you sure you want to do this?') ?>') ) { window.location.href = '<?php echo $this->getCancelUrl() ?>'; } return false;">
                    <span><?php echo __('Cancel') ?></span>
                </button>
            <?php endif; ?>
        </div>
        <div class="block-title"><strong><?php echo __('Agreement Information') ?></strong></div>
        <div class="block-content">
            <div class="table-wrapper billing-agreements-view">
                <table class="data table table-billing-agreements-view">
                    <caption class="table caption"><?php echo __('Agreement Information') ?></caption>
                    <thead>
                        <tr>
                            <th scope="col" class="col id"><?php echo __('Reference ID:'); ?></th>
                            <th scope="col" class="col status"><?php echo __('Status:'); ?></th>
                            <th scope="col" class="col created"><?php echo __('Created:'); ?></th>
                            <?php if($this->getAgreementUpdatedAt()): ?>
                                <th scope="col" class="col updated"><?php echo __('Updated:'); ?></th>
                            <?php endif; ?>
                            <th scope="col" class="col payment"><?php echo __('Payment Method:'); ?></th>
                        </tr>
                    </thead>
                    <tbody>
                    <tr>
                        <td data-th="<?php echo $this->escapeHtml(__('Reference ID:')); ?>"
                            class="col id"><?php echo $this->escapeHtml($this->getReferenceId()); ?></td>
                        <td data-th="<?php echo $this->escapeHtml(__('Status:')); ?>"
                            class="col status"><?php echo $this->getAgreementStatus() ?></td>
                        <td data-th="<?php echo $this->escapeHtml(__('Created:')); ?>"
                            class="col created"><?php echo $this->escapeHtml($this->getAgreementCreatedAt()) ?></td>
                        <?php if ($this->getAgreementUpdatedAt()): ?>
                            <td data-th="<?php echo $this->escapeHtml(__('Updated:')); ?>"
                                class="col updated"><?php echo $this->escapeHtml($this->getAgreementUpdatedAt()); ?></td>
                        <?php endif; ?>
                        <td data-th="<?php echo $this->escapeHtml(__('Payment Method:')); ?>"
                            class="col payment"><?php echo $this->getPaymentMethodTitle() ?></td>
                    </tr>
                    </tbody>
                </table>
            </div>
        </div>
    </div>
    <?php $relatedOrders = $this->getRelatedOrders() ?>
    <?php if(count($relatedOrders) > 0): ?>
    <div class="block block-billing-orders-view">
    <?php echo $this->getChildHtml('pager'); ?>
        <div class="block-title"><span><?php echo __('Related Orders') ?></span></div>
        <div class="block-content">
            <div class="table-wrapper billing-agreements-related">
                <table class="data table table-billing-agreements-related" id="related-orders-table">
                    <caption class="table caption"><?php echo __('Related Orders') ?></caption>
                    <thead>
                        <tr>
                            <th scope="col" class="col id"><?php echo __('Order #') ?></th>
                            <th scope="col" class="col date"><?php echo __('Date') ?></th>
                            <th scope="col" class="col shipto"><?php echo __('Ship To') ?></th>
                            <th scope="col" class="col total"><?php echo __('Order Total') ?></th>
                            <th scope="col" class="col status"><?php echo __('Order Status') ?></th>
                            <th scope="col" class="col actions">&nbsp;</th>
                        </tr>
                    </thead>
                    <tbody>
                    <?php foreach ($relatedOrders as $order): ?>
                        <tr>
                            <td data-th="<?php echo $this->escapeHtml(__('Order #')); ?>"
                                class="col id"><?php echo $this->getOrderItemValue($order, 'order_increment_id') ?></td>
                            <td data-th="<?php echo $this->escapeHtml(__('Date')); ?>"
                                class="col date"><?php echo $this->getOrderItemValue($order, 'created_at') ?></td>
                            <td data-th="<?php echo $this->escapeHtml(__('Ship To')); ?>"
                                class="col shipto"><?php echo $this->getOrderItemValue($order, 'shipping_address') ?></td>
                            <td data-th="<?php echo $this->escapeHtml(__('Order Total')); ?>"
                                class="col total"><?php echo $this->getOrderItemValue($order, 'order_total') ?></td>
                            <td data-th="<?php echo $this->escapeHtml(__('Order Status')); ?>"
                                class="col status"><?php echo $this->getOrderItemValue($order, 'status_label') ?></td>
                            <td data-th="" class="col actions">
                                <a href="<?php echo $this->getOrderItemValue($order, 'view_url') ?>" class="action view"><span><?php echo __('View Order') ?></span></a>
                            </td>
                        </tr>
                    <?php endforeach; ?>
                    </tbody>
                </table>
            </div>
        </div>
    </div>
    <?php endif; ?>

    <div class="actions-toolbar">
        <div class="secondary">
            <a href="<?php echo $this->getBackUrl() ?>" class="action back"><?php echo __('Back to Billing Agreements') ?></a>
        </div>
    </div>
